package com.qf.shop.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qf.shop.entity.Pay;
import com.qf.shop.mapper.PayMapper;
import com.qf.shop.model.TableData;
import com.qf.shop.pojo.QueryPay;
import com.qf.shop.service.IPayService;
import org.springframework.stereotype.Service;



@Service
public class PayServiceImpl implements IPayService {

    private PayMapper payMapper;

    public PayServiceImpl(PayMapper payMapper) {
        this.payMapper = payMapper;
    }

    @Override
    public TableData<Pay> getAllPay(QueryPay queryPay,Integer offset, Integer limit) {
        String name = queryPay.getName();
        if(null != name && !"".equals(name.trim())) {
            queryPay.setName("%" + name + "%");
        }
        String phone = queryPay.getPhone();

        if(null != phone && !"".equals(phone.trim())) {
            queryPay.setPhone("%" + phone + "%");

        }

        Page<Pay> page = PageHelper.offsetPage(offset, limit);

        payMapper.getAllPay(queryPay);

        TableData<Pay> tableData = new TableData<>();
        tableData.setRows(page.getResult());
        tableData.setTotal(page.getTotal());

        return tableData;

    }

    @Override
    public void deletePayById(Integer id) {
        payMapper.deletePay(id);

    }
}
